{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 1.算术运算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a+b: \n",
      " [[  3.   5.   7.]\n",
      " [  9.  11.  13.]]\n",
      "a+1: \n",
      " [[ 2.  3.  4.]\n",
      " [ 5.  6.  7.]]\n",
      "\n",
      "a-b: \n",
      " [[-1. -1. -1.]\n",
      " [-1. -1. -1.]]\n",
      "\n",
      "a-1: \n",
      " [[ 0.  1.  2.]\n",
      " [ 3.  4.  5.]]\n",
      "\n",
      "a*b: \n",
      " [[  2.   6.  12.]\n",
      " [ 20.  30.  42.]]\n",
      "\n",
      "a*4: \n",
      " [[  4.   8.  12.]\n",
      " [ 16.  20.  24.]]\n",
      "\n",
      "a/b: \n",
      " [[ 0.5         0.66666667  0.75      ]\n",
      " [ 0.8         0.83333333  0.85714286]]\n",
      "\n",
      "a/2: \n",
      " [[ 0.5  1.   1.5]\n",
      " [ 2.   2.5  3. ]]\n"
     ]
    }
   ],
   "source": [
    "a = np.array([[1.0, 2.0, 3.0],[4.0, 5.0, 6.0]])\n",
    "b = np.array([[2.0, 3.0, 4.0], [5.0, 6.0, 7.0]])\n",
    "\n",
    "# 计算加法\n",
    "print(\"a+b: \\n\", a+b)\n",
    "print(\"a+1: \\n\", a+1)\n",
    "\n",
    "# 计算减法\n",
    "print(\"\\na-b: \\n\", a-b)\n",
    "print(\"\\na-1: \\n\", a-1)\n",
    "\n",
    "# 乘法\n",
    "print(\"\\na*b: \\n\", a*b)\n",
    "print(\"\\na*4: \\n\", a*4)\n",
    "\n",
    "# 除法\n",
    "print(\"\\na/b: \\n\", a/b)\n",
    "print(\"\\na/2: \\n\", a/2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 2.矩阵运算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a x b: \n",
      " [[  3.   3.]\n",
      " [ 12.  12.]]\n",
      "\n",
      "a x b: \n",
      " [[  3.   3.]\n",
      " [ 12.  12.]]\n"
     ]
    }
   ],
   "source": [
    "a = np.arange(0, 6).reshape(2, 3)\n",
    "b = np.ones((3, 2))\n",
    "\n",
    "print(\"a x b: \\n\", np.dot(a, b))\n",
    "print(\"\\na x b: \\n\", a.dot(b))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 3.自增和自减运算\n",
    "\n",
    "自增自减都是本地操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a += 1: \n",
      " [ 1.  2.  3.  4.]\n",
      "\n",
      "a *= 2: \n",
      " [ 2.  4.  6.  8.]\n",
      "\n",
      "a -= 1: \n",
      " [ 1.  3.  5.  7.]\n",
      "\n",
      "a /= 2: \n",
      " [ 0.5  1.5  2.5  3.5]\n"
     ]
    }
   ],
   "source": [
    "a = np.arange(0, 4, dtype=np.float32)\n",
    "\n",
    "a += 1.0\n",
    "print(\"a += 1: \\n\", a)\n",
    "\n",
    "a *= 2.0\n",
    "print(\"\\na *= 2: \\n\", a)\n",
    "\n",
    "a -= 1.0\n",
    "print(\"\\na -= 1: \\n\", a)\n",
    "\n",
    "a /= 2.0\n",
    "print(\"\\na /= 2: \\n\", a)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 4.库函数\n",
    "\n",
    "- np.sqrt()\n",
    "- np.sin()\n",
    "- np.log()\n",
    "- np.sum()\n",
    "- np.min()\n",
    "- np.max()\n",
    "- np.mean()\n",
    "- np.std() 沿指定的轴计算标准偏差"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "sqrt:  [[ 1.          1.41421354]\n",
      " [ 1.73205078  2.        ]]\n",
      "sin:  [[ 0.84147096  0.90929741]\n",
      " [ 0.14112    -0.7568025 ]]\n",
      "log:  [[ 0.          0.69314718]\n",
      " [ 1.09861231  1.38629436]]\n",
      "sum:  10.0\n",
      "min:  1.0\n",
      "max:  4.0\n",
      "mean:  2.5\n",
      "std:  1.11803\n"
     ]
    }
   ],
   "source": [
    "a = np.arange(1, 5, dtype=np.float32).reshape(2, 2)\n",
    "\n",
    "print(\"sqrt: \", np.sqrt(a))\n",
    "print(\"sin: \", np.sin(a))\n",
    "print(\"log: \", np.log(a))\n",
    "print(\"sum: \", np.sum(a))\n",
    "print(\"min: \", np.min(a))\n",
    "print(\"max: \", np.max(a))\n",
    "print(\"mean: \", np.mean(a))\n",
    "print(\"std: \", np.std(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
